export default function (attrString) {
  if (attrString == undefined) return []
  // 当前是否在引号内
  var isYinHao = false
  // 断点
  var point = 0
  // 结果数组
  var result = []
  // 遍历attrString,而不是直接用split()
  for (let i = 0; i < attrString.length; i++) {
    let char = attrString[i]
    if (char == '"') {
      isYinHao = !isYinHao
    } else if (char == ' ' && !isYinHao) {
      // 遇见空格并且不在引号中
      if (!/^\s*$/.test(attrString.substring(point, i))) {
        result.push(attrString.substring(point, i).trim())
        point = i
      }
    }
  }
  // 循环结束最后剩余一个属性k="v"
  result.push(attrString.substring(point).trim())
  // 将["k=v","k=v"]转化为[{name:k,value:v},{name:k,value:v}]
  result = result.map((item) => {
    // 根据等号拆分
    const o = item.match(/^(.+)="(.+)"$/)
    return {
      name: o[1],
      value: o[2],
    }
  })
  return result
}
